import { Column, Entity, ManyToOne, Index } from 'typeorm';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from './user.entity';

export enum SocialProvider {
  WECHAT = 'wechat',
  QQ = 'qq',
  WEIBO = 'weibo',
}

@Entity('user_social_auths')
@Index(['provider', 'openId'], { unique: true })
export class UserSocialAuth extends BaseEntity {
  @Column({ type: 'bigint', comment: '用户ID' })
  userId: number;

  @Column({ type: 'varchar', length: 20, comment: '第三方平台' })
  provider: SocialProvider;

  @Column({ type: 'varchar', length: 100, comment: '第三方平台用户ID' })
  openId: string;

  @Column({
    type: 'varchar',
    length: 100,
    nullable: true,
    comment: '第三方平台联合ID',
  })
  unionId: string;

  // 关联关系
  @ManyToOne(() => User, (user) => user.socialAuths, { onDelete: 'CASCADE' })
  user: User;
}
